<style type="text/css">
    #addTask {
        margin-bottom: 20px;
    }
</style>
<div class=".container-fluid" id="addTask">
    <button class="btn btn-primary" data-toggle="modal" data-target="#addTaskModal">&nbsp;&nbsp;添加任务&nbsp;&nbsp;</button>
    <!-- Modal -->
    <div class="modal fade" id="addTaskModal" tabindex="-1" role="dialog" aria-labelledby="addTaskModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="addTaskModalLabel">添加任务</h4>
                </div>
                <form class="form-horizontal">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="taskName" class="col-sm-2 control-label">任务名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="taskName" placeholder="taskName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="taskPlug" class="col-sm-2 control-label">所属插件</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="taskPlug" placeholder="taskPlugin">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="taskSleepTime" class="col-sm-2 control-label">间隔时间</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="taskSleepTime" placeholder="sleepTime(ms)">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="taskNum" class="col-sm-2 control-label">批量条数</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="taskNum" placeholder="taskNum">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="taskClientIp" class="col-sm-2 control-label">客户端IP</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="taskClientIp" placeholder="taskClientIp">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">选项</label>
                        <div class="col-sm-10">
                            <label class="checkbox-inline">
                                <input type="checkbox" id="needCookie"> cookie
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="needAgent"> agent
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="needHeader"> header
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <input type="submit" value="Save changes" class="btn btn-primary" id="listFormSubmit">
                </div>
                </form>
            </div>
        </div>
    </div>
</div>
<table class="table table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>任务Id</th>
            <th>任务名</th>
            <th>所属插件</th>
            <th>间隔(ms)/批量</th>
            <th>cookie</th>
            <th>agent</th>
            <th>header</th>
            <th>运行客户端</th>
            <th>启动时间</th>
            <th>运行时常(h)</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    <?php
        $count = 1;
        foreach($data as $key => $value):
        $taskDetail = json_decode($value, true);
    ?>
    <tr>
        <td><?=$count?></td>
        <td><a href="" data-toggle="modal" data-target="#keyShow-<?=$count?>"><?=$key?></a></td>
        <td><?=$taskDetail['taskName']?></td>
        <td><?=$taskDetail['taskPlug']?></td>
        <td><a href="" data-toggle="modal" data-target="#sleepTime-<?=$count?>"><?=$taskDetail['taskSleepTime']?> / <?=$taskDetail['taskOnceNum']?></a></td>
        <td class="isNeedTag">
            <?php if (isset($taskDetail['taskCookieUrl'])):?>
                <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
            <?php else:?>
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
            <?php endif;?>
        </td>
        <td class="isNeedTag">
            <?php if (isset($taskDetail['taskAgentUrl'])):?>
            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
            <?php else:?>
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
            <?php endif;?>
        </td>
        <td class="isNeedTag">
            <?php if (isset($taskDetail['taskHeaderUrl'])):?>
            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
            <?php else:?>
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
            <?php endif;?>
        </td>
        <td><a href="" data-toggle="modal" data-target="#taskIpManage-<?=$count?>"><?=long2ip($taskDetail['taskClientIp'])?></a></td>
        <td>- : - : -</td>
        <td>-</td>
        <td>
            <?php if($taskDetail['status'] == 0):?>
            <span class="label label-danger">停止</span>
            <?php endif;?>
            <?php if($taskDetail['status'] == 1):?>
            <span class="label label-success">运行</span>
            <?php endif;?>
        </td>
        <td>
            <?php if($taskDetail['status'] == 0):?>
            <a href="" data-toggle="modal" data-target="#taskManageStart" data-taskid="<?=$key?>" data-taskname="<?=$taskDetail['taskName']?>">运行</a>
            <?php endif;?>
            <?php if($taskDetail['status'] == 1):?>
            <a href="" data-toggle="modal" data-target="#taskManageStop" data-taskid="<?=$key?>" data-taskname="<?=$taskDetail['taskName']?>">停止</a>
            <?php endif;?>
             | 删除
        </td>
    </tr>
    <?php
        $count++;
        endforeach;
    ?>
    </tbody>
    <tfoot>
        <tr>
            <th>#</th>
            <th>任务Id</th>
            <th>任务名</th>
            <th>所属插件</th>
            <th>间隔时间(ms)</th>
            <th>cookie</th>
            <th>agent</th>
            <th>header</th>
            <th>运行客户端</th>
            <th>启动时间</th>
            <th>运行时常(h)</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </tfoot>
</table>

<?php
        $count = 1;
        foreach($data as $key => $value):
        $taskDetail = json_decode($value, true);
?>
<div class="modal fade" id="keyShow-<?=$count?>" tabindex="-1" role="dialog" aria-labelledby="keyShow-<?=$count?>Label">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="keyShow-<?=$count?>Label"><?=$taskDetail['taskName']?> - 详情</h4>
            </div>
            <div class="modal-body">
                <table class="table">
                    <thead><tr><th>key</th><th>value</th></tr></thead>
                    <?php foreach($taskDetail as $k => $v):?>
                        <?php if ($k == 'taskClientIp'):?>
                            <tr><td><?=$k?></td><td><?=long2ip($v)?></td></tr>
                        <?php else: ?>
                            <tr><td><?=$k?></td><td><?=$v?></td></tr>
                        <?php endif;?>
                    <?php endforeach?>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="sleepTime-<?=$count?>" tabindex="-1" role="dialog" aria-labelledby="sleepTime-<?=$count?>Label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="sleepTime-<?=$count?>Label"><?=$taskDetail['taskName']?> - 间隔(ms)/批量 - 修改</h4>
            </div>
            <form class="form-horizontal">
            <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-2 control-label">任务名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" placeholder="<?=$taskDetail['taskName']?>" disabled>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">任务Id</label>
                    <div class="col-sm-10">
                        <input id="updateTaskId<?=$count?>" type="text" class="form-control" placeholder="<?=$key?>" value="<?=$key?>" disabled>
                    </div>
                </div>
                <div class="form-group">
                    <label for="updateTaskSleepTime<?=$count?>" class="col-sm-2 control-label">间隔时间</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="updateTaskSleepTime<?=$count?>" value="<?=$taskDetail['taskSleepTime']?>">
                    </div>
                </div>
                <div class="form-group">
                    <label for="updateTaskNum<?=$count?>" class="col-sm-2 control-label">批量条数</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="updateTaskNum<?=$count?>" value="<?=$taskDetail['taskOnceNum']?>">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <input type="submit" value="Save changes" class="btn btn-primary updateListFormSubmit" dataCountId="<?=$count?>">
            </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="taskIpManage-<?=$count?>" tabindex="-1" role="dialog" aria-labelledby="taskIpManage-<?=$count?>Label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="taskIpManage-<?=$count?>Label"><?=$taskDetail['taskName']?> - 客户端IP管理</h4>
            </div>
            <form class="form-horizontal">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">任务名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" value="<?=$taskDetail['taskName']?>" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">任务Id</label>
                        <div class="col-sm-10">
                            <input id="updateIpTaskId<?=$count?>" type="text" class="form-control" value="<?=$key?>" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">原客户端Ip</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" value="<?=long2ip($taskDetail['taskClientIp'])?>" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="updateIpTaskNowIp<?=$count?>" class="col-sm-2 control-label">现客户端Ip</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="updateIpTaskNowIp<?=$count?>">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <input type="submit" value="Save changes" class="btn btn-primary updateListIpFormSubmit" dataCountId="<?=$count?>">
                </div>
            </form>
        </div>
    </div>
</div>


<?php $count++; endforeach;?>

<div class="modal fade" id="taskManageStart" tabindex="-1" role="dialog" aria-labelledby="taskManageStartLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="taskManageStartLabel"><?=$taskDetail['taskName']?> - 管理</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="taskManageStop" tabindex="-1" role="dialog" aria-labelledby="taskManageStopLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="taskManageStopLabel"><?=$taskDetail['taskName']?> - 管理</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
